package cn.sixos.bo;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.forten.utils.system.BeanPropertyUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.sixos.dao.HibernateDao;
import cn.sixos.entity.User;
import cn.sixos.vo.UserVo;

@Service("loginBo")
public class LoginBo {
	@Resource
	private HibernateDao hibernateDao;

	// 登陆
	@Transactional
	public UserVo doLogin(String name, String password) {
		String hql = "FROM User WHERE userName=:n AND password=:p";
		Map<String, Object> map = new HashMap<>();
		map.put("n", name);
		map.put("p", password);
		User user = hibernateDao.findUniqueObject(hql, map);
		if (user == null) {
			throw new RuntimeException("用户不存在！");
		}
		UserVo vo = new UserVo();
		BeanPropertyUtil.copy(vo, user);
		return vo;
	}
}
